package yuan;

import java.io.IOException;
import java.util.Arrays;
import java.util.Map;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;


	@Override
	public void init() throws ServletException {
//		super.init();
		System.out.println("eeeeee");
		final Thread thread=new Thread(){
			@Override
			public void run() {
				super.run();
				//
				while (true){
					try {
						System.out.println("这是后台返回的消息");
						WebSocket ws = new WebSocket();
						ws.onMessage("这是后台返回的消息");
						Thread.sleep(1000);
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		};
		thread.start();

	}


	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		response.setContentType("text/plain");
//		response.setCharacterEncoding("utf-8");
//		response.getWriter().write("hello world111");

		response.sendRedirect("hello.jsp");
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
